package com.theydream.qeechain.globaldata;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.database.SQLException;
import android.location.Location;

import com.theydream.qeechain.db.DBHelper;
import com.theydream.qeechain.globaldata.definition.BattleQee;
import com.theydream.qeechain.globaldata.definition.Effect;
import com.theydream.qeechain.globaldata.definition.Qee;

public class GlobalData {
	private static GlobalData instance;
	private double userLongtitude;
	private double userLantitude;
	private Location userLocation;
	private float petDegree;
	private int caughtPetImage;

	// Battle Data
	private Map<String, BattleQee> petListBattle = new HashMap<String, BattleQee>();
	private Map<String, Qee> petList = new HashMap<String, Qee>();
	// private SequenceLogic moveSequence;
	private Map<String, Effect> consumables = new HashMap<String, Effect>();
	private Map<String, Effect> skills = new HashMap<String, Effect>();
	private List<Qee> petInUse = new ArrayList<Qee>();

	private String arID;

	// Database Helper
	private DBHelper dbhelper;

	// private constructor
	private GlobalData() {

	}

	// Initialize GlobatData
	public static void initialize(Context appContext) {
		if (null == instance) {

			instance = new GlobalData();

			// Initialize database
			instance.dbhelper = new DBHelper(appContext);

			try {
				instance.dbhelper.createDataBase();
			} catch (IOException e) {
				throw new Error("Unable to create database");
			}

			try {
				instance.dbhelper.openDataBase();
			} catch (SQLException e) {
				throw e;
			}
		}
	}

	public static synchronized GlobalData getInstance() {
		return instance;
	}

	public Location getUserLocation() {
		return userLocation;
	}

	public void setUserLocation(Location userLocation) {
		this.userLocation = userLocation;
	}

	public double getUserLongtitude() {
		return userLongtitude;
	}

	public void setUserLongtitude(double userLongtitude) {
		this.userLongtitude = userLongtitude;
	}

	public double getUserLantitude() {
		return userLantitude;
	}

	public void setUserLantitude(double userLantitude) {
		this.userLantitude = userLantitude;
	}

	/**
	 * @return the petListBattle
	 */
	public Map<String, BattleQee> getPetListBattle() {
		return petListBattle;
	}

	/**
	 * @param petList
	 *            the petListBattle to set
	 */
	public void setPetListBattle(Map<String, BattleQee> petList) {
		this.petListBattle = petList;
	}

	// /**
	// * @return the moveSequence
	// */
	// public SequenceLogic getMoveSequence() {
	// return moveSequence;
	// }
	//
	//
	// /**
	// * @param moveSequence the moveSequence to set
	// */
	// public void setMoveSequence(SequenceLogic moveSequence) {
	// this.moveSequence = moveSequence;
	// }

	public Map<String, Qee> getPetList() {
		return petList;
	}

	public void setPetList(Map<String, Qee> petList) {
		this.petList = petList;
	}

	/**
	 * @return the consumables
	 */
	public Map<String, Effect> getConsumables() {
		return consumables;
	}

	/**
	 * @param consumables
	 *            the consumables to set
	 */
	public void setConsumables(Map<String, Effect> consumables) {
		this.consumables = consumables;
	}

	/**
	 * @return the skills
	 */
	public Map<String, Effect> getSkills() {
		return skills;
	}

	/**
	 * @param skills
	 *            the skills to set
	 */
	public void setSkills(Map<String, Effect> skills) {
		this.skills = skills;
	}

	/**
	 * @return the dbhelper
	 */
	public DBHelper getDbhelper() {
		return dbhelper;
	}

	/**
	 * @param dbhelper
	 *            the dbhelper to set
	 */
	public void setDbhelper(DBHelper dbhelper) {
		this.dbhelper = dbhelper;
	}

	public String getArID() {
		return arID;
	}

	public void setArID(String arID) {
		this.arID = arID;
	}

	public void setPetInUse(List<Qee> petInUse) {
		this.petInUse = petInUse;
	}

	public List<Qee> getPetInUse() {
		return petInUse;
	}

	public float getPetDegree() {
		return petDegree;
	}

	public void setPetDegree(float petDegree) {
		this.petDegree = petDegree;
	}

	public int getCaughtPetImage() {
		return caughtPetImage;
	}

	public void setCaughtPetImage(int i) {
		this.caughtPetImage = i;
	}
}
